<template>
	<view class="container">
		<view class="form">
			<image src="../../../static/1691584656227.png" style="margin-bottom: 3vh;"></image>
			<view class="form-item"> <text class="label">姓名：</text> <input class="input" type="text" v-model="form.name"
					placeholder="请输入姓名" /> </view>
			<view class="form-item"> <text class="label">电话：</text> <input class="input" type="tel" v-model="form.phone"
					placeholder="请输入电话" /> </view>
			<button class="submit-btn" @click="submitForm">提交申请</button>
		</view>
	</view>
</template>
<script>
	import {
		authToPostman
	} from "../../../api/logistics/logistics";
	import {
		findIdByName
	} from "../../../api/logistics/logistics";
	import {
		addPostman
	} from "../../../api/logistics/logistics";
	export default {
		data() {
			return {
				form: {
					userId: 0,
					name: '', //姓名
					phone: '', //电话
					deviceId: '', //设备id
				},

			};
		},
		methods: {
			submitForm() {
				uni.getSystemInfo({
					success: (res) => {
						console.info(res.deviceId)
						this.form.deviceId = res.deviceId
						let user = {
							roleId: 101
						}
						authToPostman(
							user
						).then(res => {
							
							if (this.form.deviceId) {
								addPostman(this.form)
								uni.showToast({
									title: '申请成功',
									icon: 'none', // 提示图标，可选值：success/loading/none
									duration: 2000, // 提示框显示时间，单位为ms，默认值为1500
									mask: true // 是否显示透明蒙层，防止触摸穿透，默认值为false
								})
								 uni.navigateBack({
								        delta: 1 // 返回的页面数，1 表示返回上一级页面
								      })
							} else {
								uni.showToast({
									title: '只能在移动端申请',
									icon: 'none', // 提示图标，可选值：success/loading/none
									duration: 2000, // 提示框显示时间，单位为ms，默认值为1500
									mask: true // 是否显示透明蒙层，防止触摸穿透，默认值为false
								})
							}

						}).catch(mes => {
							console.info(mes)
						})
					}

				})



			}
		},
		async created() {
			this.form.userId = this.$store.state.user.userId

		}
	};
</script>
<style>
	.container {
		padding: 20rpx;
	}

	.title {
		font-size: 32rpx;
		font-weight: bold;
		text-align: center;
		margin-bottom: 20rpx;
	}

	.form {
		background-color: #fff;
		padding: 20rpx;
		border-radius: 10rpx;
	}

	.form-item {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.label {
		font-size: 28rpx;
		width: 160rpx;
	}

	.input {
		flex: 1;
		height: 60rpx;
		border: 1rpx solid #ccc;
		border-radius: 5rpx;
		padding: 10rpx;
	}

	.upload-btn {
		width: 130rpx;
		height: 60rpx;
		background-color: #f90;
		color: #fff;
		border-radius: 5rpx;
		margin-right: 10rpx;
	}

	.photo {
		width: 120rpx;
		height: 120rpx;
		border-radius: 5rpx;
		object-fit: cover;
	}

	.submit-btn {
		width: 100%;
		height: 80rpx;
		background-color: #f90;
		color: #fff;
		border-radius: 5rpx;
		font-size: 32rpx;
		margin-top: 20rpx;
	}
</style>